home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / C⁄C++ OS8 / LayerGroups / TabPanel.cp < prev    next >
Encoding:
Text File  |  1998-10-23  |  6.7 KB  |  357 lines  |  [TEXT/CWIE]

  1. // TabPanel.cp
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <Resources.h>
  11. #include <Sound.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include <Appearance.h>
  15.  
  16. #include "Globals.h"
  17. #include "ResourceDefs.h"
  18. #include "DoScrap.h"
  19. #include "Miscellany.h"
  20. #include "Scrolling.h"
  21. #include "ControlUtils.h"
  22. #include "DDocData.h"
  23. #include "LayerGroupsEngine.h"
  24. #include "LayerGroupsDoc.h"
  25.  
  26. #include "TabPanel.h"
  27.  
  28.  
  29. //----------
  30. void    TabPanel::Create (
  31.     AMDoc*            inDoc,
  32.     DDocData*        inData)
  33. {
  34.     TabPanel*        winObj = new TabPanel;
  35.  
  36.     if (winObj != nil) {
  37.         winObj->Open (inDoc);
  38.         winObj->ConnectToData (inData);
  39.     }
  40. }
  41.  
  42. //----------
  43. TabPanel::TabPanel ()
  44. {
  45.     mData = nil;
  46. }
  47.  
  48. //----------
  49. TabPanel::~TabPanel ()
  50. {
  51. }
  52.  
  53. //----------
  54. LayerGroupsEngine*    TabPanel::GetEngine ()
  55. {
  56.     return (LayerGroupsEngine*) mDoc->mEngine;
  57. }
  58.  
  59. //----------
  60. void    TabPanel::Open (
  61.     AMDoc*            inDoc)
  62. {
  63.     WindowPtr        window;
  64.     Handle            wftb;
  65.  
  66.     mDoc = inDoc;
  67.  
  68.     window = GetNewCWindow (WIND_TabPanel, nil, (WindowPtr) -1L);
  69.     if (mDoc->mEngine->GetFilename () [0] != 0) {
  70.         SetWTitle (window, mDoc->mEngine->GetFilename ());
  71.     }
  72.     mWindow = window;
  73.     ((LayerGroupsDoc*)mDoc)->mTabPanelPtr = window;
  74.  
  75.     SetWindowKind (window, 'AM');
  76.     SetWRefCon (window, (long) this);
  77.     SetPort (window);
  78.     SetInfo (window);
  79.  
  80.     wftb = ::GetResource ('Wftb', WIND_TabPanel);
  81.  
  82.     CreateRootControl (window, &mRootControl);
  83.  
  84.     vScroll = nil;
  85.     hScroll = nil;
  86.  
  87.  
  88.     mTabsHandle = ::GetNewControl (CNTL_Tabs, window);
  89.     SetWindowItemFont (mTabsHandle, wftb, 1);
  90.  
  91.  
  92.     mFredHandle = ::GetNewControl (CNTL_Fred, window);
  93.     EmbedControl (mFredHandle, mTabsHandle);
  94.     SetWindowItemFont (mFredHandle, wftb, 2);
  95.  
  96.     mTheseWindowsShowSeveralVaLabel = GetNewControl (CNTL_TheseWindowsShowSeveralVa, window);
  97.     EmbedControl (mTheseWindowsShowSeveralVaLabel, mFredHandle);
  98.     SetWindowItemFont (mTheseWindowsShowSeveralVaLabel, wftb, 3);
  99.     SetControlFromTEXT (mTheseWindowsShowSeveralVaLabel, TEXT_TheseWindowsShowSeveralVa);
  100.  
  101.  
  102.     mGeorgeHandle = ::GetNewControl (CNTL_George, window);
  103.     EmbedControl (mGeorgeHandle, mTabsHandle);
  104.     SetWindowItemFont (mGeorgeHandle, wftb, 4);
  105.  
  106.     mEditTextHandle = ::GetNewControl (CNTL_EditText, window);
  107.     EmbedControl (mEditTextHandle, mGeorgeHandle);
  108.     SetWindowItemFont (mEditTextHandle, wftb, 5);
  109.  
  110.  
  111.     mHarryHandle = ::GetNewControl (CNTL_Harry, window);
  112.     EmbedControl (mHarryHandle, mTabsHandle);
  113.     SetWindowItemFont (mHarryHandle, wftb, 6);
  114.  
  115.     mScrollBarHandle = ::GetNewControl (CNTL_ScrollBar, window);
  116.     EmbedControl (mScrollBarHandle, mHarryHandle);
  117.     SetWindowItemFont (mScrollBarHandle, wftb, 7);
  118.  
  119.     AdvanceKeyboardFocus (window);
  120.  
  121.     ShowWindow (window);
  122. }
  123.  
  124. //----------
  125. void    TabPanel::Close ()
  126. {
  127.     mData->RemoveResponder (this);
  128.  
  129.     ((LayerGroupsDoc*)mDoc)->mTabPanelPtr = nil;
  130.     SetInfo (nil);
  131.     HideWindow (mWindow);
  132.     DisposeWindow (mWindow);
  133.  
  134.     delete this;
  135. }
  136.  
  137. //----------
  138. void    TabPanel::ConnectToData (
  139.     DDocData*        inData)
  140. {
  141.     mData = inData;
  142.     mData->AddResponder (this);
  143.  
  144.     SetControlValue (mTabsHandle, mData->GetTabs ());
  145.     SetLayerGroupValue (mTabsHandle, GetControlValue (mTabsHandle));
  146.     SetClockDateTime (mEditTextHandle, mData->GetEditText ());
  147.     SetControlValue (mScrollBarHandle, mData->GetScrollBar ());
  148. }
  149.  
  150. //----------
  151. void    TabPanel::DataChanged (
  152.     long        inDataID)
  153. {
  154.     if (inDataID == idTabs) {
  155.         SetControlValue (mTabsHandle, mData->GetTabs ());
  156.         SetLayerGroupValue (mTabsHandle, mData->GetTabs ());
  157.     }
  158.     if (inDataID == idEditText) {
  159.         SetClockDateTime (mEditTextHandle, mData->GetEditText ());
  160.     }
  161.     if (inDataID == idScrollBar) {
  162.         SetControlValue (mScrollBarHandle, mData->GetScrollBar ());
  163.     }
  164. }
  165.  
  166. //----------
  167. void    TabPanel::Control (
  168.     ControlHandle        whichControl,
  169.     short                whichPart,
  170.     Point                where)
  171. {
  172.     Rect            bounds;
  173.     short            newValue;
  174.  
  175.     ExitCurField ();
  176.  
  177.     if (whichControl == mTabsHandle) {
  178.         if (TrackClick (mTabsHandle, where) != 0) {
  179.             mData->SetTabs (GetControlValue (mTabsHandle));
  180.         }
  181.     }
  182.     if (whichControl == mEditTextHandle) {
  183.         HandleEditClick (mEditTextHandle, where);
  184.         mData->SetEditText (GetClockDateTime (mEditTextHandle));
  185.     }
  186.     if (whichControl == mScrollBarHandle) {
  187.         HandleControlClick (mScrollBarHandle, where, curEvent.modifiers, nil);
  188.         mData->SetScrollBar (GetControlValue (mScrollBarHandle));
  189.     }
  190. }
  191.  
  192. //----------
  193. void    TabPanel::MouseIn (
  194.     Point        where,
  195.     short        modifiers)
  196. {
  197.     Rect        bounds;
  198.  
  199. }
  200.  
  201. //----------
  202. void    TabPanel::ExitCurField ()
  203. {
  204.     ControlHandle    focus;
  205.  
  206.     GetKeyboardFocus (mWindow, &focus);
  207.  
  208.     if (focus == nil) {
  209.         // nothing to exit
  210.  
  211.     } else if (focus == mEditTextHandle) {
  212.         mData->SetEditText (GetClockDateTime (mEditTextHandle));
  213.     }
  214. }
  215.  
  216. //----------
  217. void    TabPanel::TypeIn (
  218.     char        ch)
  219. {
  220.     ControlHandle    focus;
  221.     SInt16            keyCode;
  222.  
  223.     GetKeyboardFocus (mWindow, &focus);
  224.  
  225.     if ((ch == charEnter)
  226.     ||  (ch == charReturn)) {
  227.         ExitCurField ();
  228.     } else if (ch == charEsc) {
  229.     } else if (ch == charTab) {
  230.         DoTab ((curEvent.modifiers & optionKey) != 0);
  231.     } else if (focus != nil) {
  232.         keyCode = (SInt16)(curEvent.message & keyCodeMask);
  233.         HandleControlKey (focus, keyCode, ch, (SInt16)curEvent.modifiers);
  234.         mDoc->mEngine->SetDirty ();
  235.     } else {
  236.         SysBeep (1);
  237.     }
  238. }
  239.  
  240. //----------
  241. void    TabPanel::Resize ()
  242. {
  243.     /* application-specific code to resize items in window */
  244. }
  245.  
  246. //----------
  247. void    TabPanel::Scroll (
  248.     short        newValue,
  249.     short        oldValue)
  250. {
  251.     /* application-specific code to scroll window */
  252.     if (gWhichScroll == vScroll) {
  253.     } else {    // horizontal
  254.     }
  255. }
  256.  
  257. //----------
  258. void    TabPanel::DoUndo ()
  259. {
  260. } // DoUndo
  261.  
  262. //----------
  263. void    TabPanel::DoCut ()
  264. {
  265.     TEHandle        curTE = GetCurTE ();
  266.  
  267.     if (curTE != nil) {
  268.         TECut (curTE);
  269.         mDoc->mEngine->SetDirty ();
  270.         scrapDirty = true;
  271.     }
  272. } // DoCut
  273.  
  274. //----------
  275. void    TabPanel::DoCopy ()
  276. {
  277.     TEHandle        curTE = GetCurTE ();
  278.  
  279.     if (curTE != nil) {
  280.         TECopy (curTE);
  281.         scrapDirty = true;
  282.     }
  283. } // DoCopy
  284.  
  285. //----------
  286. void    TabPanel::DoPaste ()
  287. {
  288.     TEHandle        curTE = GetCurTE ();
  289.  
  290.     if (curTE != nil) {
  291.         TEPaste (curTE);
  292.         mDoc->mEngine->SetDirty ();
  293.     }
  294. } // DoPaste
  295.  
  296. //----------
  297. void    TabPanel::DoClear ()
  298. {
  299.     TEHandle        curTE = GetCurTE ();
  300.  
  301.     if (curTE != nil) {
  302.         TEDelete (curTE);
  303.         mDoc->mEngine->SetDirty ();
  304.     }
  305. } // DoClear
  306.  
  307. //----------
  308. void    TabPanel::DoSelectAll ()
  309. {
  310.     TEHandle        curTE = GetCurTE ();
  311.  
  312.     if (curTE != nil) {
  313.         TESetSelect (0, 32767, curTE);
  314.     }
  315. } // DoSelectAll
  316.  
  317. //----------
  318. void    TabPanel::DoShowClipboard ()
  319. {
  320. } // DoShowClipboard
  321.  
  322. //----------
  323. Boolean        TabPanel::DoCommand (
  324.     long        inCommand)
  325. {
  326.     Boolean        result = true;
  327.  
  328.     switch (inCommand) {
  329.         case cmdUndo:
  330.                 DoUndo ();
  331.             break;
  332.         case cmdCut:
  333.                 DoCut ();
  334.             break;
  335.         case cmdCopy:
  336.                 DoCopy ();
  337.             break;
  338.         case cmdPaste:
  339.                 DoPaste ();
  340.             break;
  341.         case cmdClear:
  342.                 DoClear ();
  343.             break;
  344.         case cmdSelectAll:
  345.                 DoSelectAll ();
  346.             break;
  347.         case cmdShowClipboard:
  348.                 DoShowClipboard ();
  349.             break;
  350.  
  351.         default:
  352.                 result = false;
  353.     } // switch
  354.  
  355.     return result;
  356. }
  357.